
/**
* @module create-message
* @author: Hjava
* @description: 创建消息模块，用于发送消息时构造消息体
* @since: 2018-07-23 12:31:53
*/
Object.defineProperty(exports, "__esModule", { value: true });
var models_1 = __webpack_require__(/*! ../models */ "./src/extra/models/index.ts");
function createMessage(messageDatum) {
    var sessionType = messageDatum.sessionType;
    switch (sessionType) {
        case models_1.Session.TYPE.CHAT: {
            return createChatMessage(messageDatum);
        }
        case models_1.Session.TYPE.CHAT2: {
            return createChatMessage2(messageDatum);
        }
        case models_1.Session.TYPE.GROUP_CHAT: {
            return createGroupChatMessage(messageDatum);
        }
        case models_1.Session.TYPE.PUB_CHAT: {
            return createPubChatMessage(messageDatum);
        }
        case models_1.Session.TYPE.PUB_CHAT2: {
            return createPubChatMessage2(messageDatum);
        }
        case models_1.Session.TYPE.CS_CHAT: {
            return createCSChatMessage(messageDatum);
        }
        case models_1.Session.TYPE.CS_CHAT2: {
            return createCSChatMessage2(messageDatum);
        }
    }
}
exports.default = createMessage;
function createChatMessage(_a) {
    var body = _a.body, from = _a.from, to = _a.to, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, uuid = _a.uuid;
    var message = IMBodyToMessage(type, body);
    if (true) {
        var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
        return new IM.Session.IMSendMsgReq({
            fromUid: from,
            toUid: to,
            type: type,
            message: message,
            fromName: fromName,
            toAppId: toAppId,
            extension: extension,
            channel: channelId,
            uuid: uuid
        });
    }
}
function createChatMessage2(_a) {
    var body = _a.body, from = _a.from, to = _a.to, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, sid = _a.sid, uuid = _a.uuid;
    var message = IMBodyToMessage(type, body);
    if (true) {
        var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
        return new IM.Session.IMSendMsg2({
            fromUid: from,
            toUid: to,
            type: type,
            message: message,
            fromName: fromName,
            toAppId: toAppId,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            sid: sid
        });
    }
}
function createGroupChatMessage(_a) {
    var body = _a.body, from = _a.from, to = _a.to, fromName = _a.fromName, groupName = _a.groupName, type = _a.type, extension = _a.extension, channelId = _a.channelId, uuid = _a.uuid, receipt = _a.receipt;
    var message = IMBodyToMessage(type, body);
    if (true) {
        var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
        return new IM.Session.IMSendGroupMsgReq({
            fromUid: from,
            toGuid: to,
            type: type,
            message: message,
            fromName: fromName,
            groupName: groupName,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            receipt: receipt
        });
    }
}
function createPubChatMessage(_a) {
    var body = _a.body, from = _a.from, to = _a.to, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, uuid = _a.uuid, _b = _a.direction, direction = _b === void 0 ? 1 : _b;
    var message = PubBodyToMessage(type, body);
    if (true) {
        var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
        return new PUB.Session.PubSendMsgReq({
            fromUid: from,
            toUid: to,
            toAppId: 0,
            type: type,
            message: message,
            fromName: fromName,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            direction: direction
        });
    }
}
function createPubChatMessage2(_a) {
    var body = _a.body, from = _a.from, to = _a.to, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, sid = _a.sid, uuid = _a.uuid;
    var message = PubBodyToMessage(type, body);
    if (true) {
        var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
        return new PUB.Session.PubSendMsgReq2({
            fromUid: from,
            toUid: to,
            toAppId: 0,
            type: type,
            message: message,
            fromName: fromName,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            sid: sid
        });
    }
}
function createCSChatMessage(_a) {
    var _b;
    var body = _a.body, from = _a.from, to = _a.to, belongTo = _a.belongTo, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, uuid = _a.uuid, _c = _a.direction, direction = _c === void 0 ? 1 : _c;
    var _d = (direction === 1 ? to : from).split('_'), pubId = _d[0], peerUid = _d[1];
    if ((!pubId || !peerUid) && belongTo) {
        _b = (direction === 1 ? belongTo : from).split('_'), pubId = _b[0], peerUid = _b[1];
    }
    var message = PubBodyToMessage(type, body);
    if (true) {
        var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
        return new PUB.Session.PubSendMsgKFReq({
            senderUid: direction === 1 ? from : peerUid,
            receiverUid: direction === 1 ? peerUid : to,
            receiverAppId: 0,
            pubUid: pubId,
            type: type,
            message: message,
            fromName: fromName,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            direction: direction
        });
    }
}
function createCSChatMessage2(_a) {
    var _b;
    var body = _a.body, from = _a.from, to = _a.to, belongTo = _a.belongTo, fromName = _a.fromName, type = _a.type, toAppId = _a.toAppId, extension = _a.extension, channelId = _a.channelId, sid = _a.sid, uuid = _a.uuid, _c = _a.direction, direction = _c === void 0 ? 1 : _c;
    var _d = (direction === 1 ? to : from).split('_'), pubId = _d[0], peerUid = _d[1];
    if ((!pubId || !peerUid) && belongTo) {
        _b = (direction === 1 ? belongTo : from).split('_'), pubId = _b[0], peerUid = _b[1];
    }
    var message = PubBodyToMessage(type, body);
    if (true) {
        var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
        return new PUB.Session.PubSendMsgKFReq2({
            senderUid: from,
            receiverUid: peerUid,
            receiverAppId: 0,
            pubUid: pubId,
            type: type,
            message: message,
            fromName: fromName,
            extension: extension,
            channel: channelId,
            uuid: uuid,
            sid: sid
        });
    }
}
function IMBodyToMessage(type, body) {
    switch (type) {
        case models_1.Message.TYPE.MSG_TYPE_TEXT: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {text}
                return new IM.Message.IMTextMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VOICE: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {url, stamp, duration}
                return new IM.Message.IMAudioMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VIDEO: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {}
                return new IM.Message.IMVideoMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_IMAGE: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {thumbnail|normal|origin|type|originSize}
                return new IM.Message.IMImageMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_CALENDAR: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {cid|dtstart|dtend|summary|location|participant(JSON)|remark|trigger}
                return new IM.Message.IMCalendarMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_LINK: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {title|content|image|link}
                return new IM.Message.IMLinkMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_MULTI_LINK: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {num|content(JSON)}
                return new IM.Message.IMMultiLinkMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_FILE: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {id|url|name|format|size}
                return new IM.Message.IMFileMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GPS: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {}
                return new IM.Message.IMGPSMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VCARD: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {uid|name|account|type(1/2)|subType(1)}//type代表名片类型, 若为个人名片则置为1, 若为公众号名片则置为2; subtype表示公众号的子类型
                return new IM.Message.IMVCardMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_EMOTION: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {category|type|name}
                return new IM.Message.IMEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_EVENT: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {}
                return new IM.Message.IMEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_CUSTOM: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                // body {templateName|contentTitle|content|linkName|link}
                return new IM.Message.IMCustomInfo(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GENERAL: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMGeneralMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_NEWEMOTION: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMNewEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_QUOTE: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMQuoteMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GVCARD: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMGVCardInfo(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_NOTICE: {
            if (true) {
                return null;
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_RED_PACKET: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMRedPacketInfo(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_PCALL: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMPCallMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_DYNAMIC: {
            if (true) {
                var IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
                return new IM.Message.IMDynamicMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_TT: {
            if (true) {
                return null;
            }
            break;
        }
    }
}
function PubBodyToMessage(type, body) {
    switch (type) {
        case models_1.Message.TYPE.MSG_TYPE_TEXT: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubTextMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VOICE: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubAudioMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VIDEO: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubVideoMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_IMAGE: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubImageMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_CALENDAR: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubCalendarMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_LINK: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubLinkMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_MULTI_LINK: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubMultiLinkMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_FILE: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubFileMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GPS: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubGPSMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_VCARD: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubVCardMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_EMOTION: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_EVENT: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_CUSTOM: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubCustomInfo(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GENERAL: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubGeneralMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_NEWEMOTION: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubNewEmotionMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_QUOTE: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubQuoteMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_GVCARD: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubGVcardMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_NOTICE: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubNoticeMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_RED_PACKET: {
            if (true) {
                return null;
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_PCALL: {
            if (true) {
                return null;
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_DYNAMIC: {
            if (true) {
                var PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
                return new PUB.Message.PubDynamicMessage(body);
            }
            break;
        }
        case models_1.Message.TYPE.MSG_TYPE_TT: {
            if (true) {
                return null;
            }
            break;
        }
    }
}


//# sourceURL=webpack://MTDX/./src/extra/utils/create-message.ts?